package com.trkj.dao.jpa;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.trkj.pojos.YzrMedPurch;

public interface IYzrMedPurchDAO extends CrudRepository<YzrMedPurch, String> {
	//根据编号前缀查询出最大的编号
	@Query("select max(mp.purchId) from YzrMedPurch mp where mp.purchId like ?1%")
	public String findID(String a);
	
	//根据审批人查找计划 
	@Query("select mp from YzrMedPurch mp where mp.purchAutdit=?1 and purchAutditState='待审核' order by mp.purchZdTime desc")
	public List<YzrMedPurch> findPlanByAutdit(BigDecimal staffId,Pageable pageable);
	
	//查询所有计划
	@Query("select mp from YzrMedPurch mp order by mp.purchId desc")
	public List<YzrMedPurch> findAll(Pageable pageable);
	
	//根据制定人查找采购计划
	@Query("select mp from YzrMedPurch mp where mp.purchMakepeople=?1")
	public List<YzrMedPurch> findByPurchName(String purchName,Pageable pageable);
		
	//根据状态查找采购计划
	@Query("select mp from YzrMedPurch mp where mp.purchAutditState=?1")
	public List<YzrMedPurch> findByAutditState(String title,Pageable pageable);	
	
	//根据标题查找采购计划
	@Query("select mp from YzrMedPurch mp where mp.purchTitle like %?1%")
	public List<YzrMedPurch> findByTitle(String state,Pageable pageable);	
	
	//根据采购状态查找采购计划
	@Query("select mp from YzrMedPurch mp where mp.purchState like %?1%")
	public List<YzrMedPurch> findByPurchState(String state,Pageable pageable);
	
	//查找出‘未采购’并且‘已通过’的采购计划单
	@Query("select mp from YzrMedPurch mp where mp.purchAutditState='已通过' and mp.purchState='未采购'")
	public List<YzrMedPurch> findByStateAndAutState(Pageable pageable);
	
	//统计制作人的数量
	@Query("select count(*) from YzrMedPurch mp where mp.purchMakepeople=?1")
	public long findByNameCount(String purchName);
	
	//统计状态的数量
	@Query("select count(*) from YzrMedPurch mp where mp.purchAutditState=?1")
	public long findByStateCount(String state);
	
	//统计标题的数量
	@Query("select count(*) from YzrMedPurch mp where mp.purchTitle=?1")
	public long findByTitleCount(String state);
	
	//统计采购状态数量
	@Query("select count(*) from YzrMedPurch mp where mp.purchState=?1")
	public long findByPurchStateCount(String state);
}
